package org.rambadger.command.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Collection;
import java.util.HashSet;

public class UniqueCollectionValidator implements ConstraintValidator<Unique, Collection<?>> {

    @Override
    public void initialize(Unique constraintAnnotation) {
    }

    @Override
    public boolean isValid(Collection<?> values, ConstraintValidatorContext context) {
        return new HashSet<>(values).size() == values.size();
    }
}
